@model List<CaipuGuanliXitong.Models.WeeklyMenu>

@{
    ViewData["Title"] = "删除每周菜谱";
}

<h2>删除每周菜谱</h2>

<h3>您确定要删除这一周的菜谱吗？</h3>
<div>
    <h4>菜谱详情</h4>
    <hr />
    
    <div class="row">
        <div class="col-md-12">
            <form method="get" action="@Url.Action("Index")" class="form-inline">
                <div class="form-group">
                    <label for="startDate">周开始日期:</label>
                    <input type="date" name="startDate" value="@ViewBag.StartDate.ToString("yyyy-MM-dd")" class="form-control" readonly />
                </div>
            </form>
        </div>
    </div>

    <table class="table table-bordered">
        <thead>
            <tr>
                <th>星期</th>
                <th>早餐</th>
                <th>午餐</th>
                <th>晚餐</th>
            </tr>
        </thead>
        <tbody>
            @{
                string[] weekdays = { "周一", "周二", "周三", "周四", "周五", "周六", "周日" };
                int[] dayNumbers = { 1, 2, 3, 4, 5, 6, 7 };
                string[] meals = { "早餐", "午餐", "晚餐" };
                int[] mealNumbers = { 1, 2, 3 };
            }
            
            @for (int i = 0; i < weekdays.Length; i++)
            {
                <tr>
                    <td>@weekdays[i]</td>
                    @for (int j = 0; j < meals.Length; j++)
                    {
                        <td>
                            @{
                                var menu = Model.FirstOrDefault(m => m.DayOfWeek == dayNumbers[i] && m.MealType == mealNumbers[j]);
                                if (menu != null)
                                {
                                    if (!string.IsNullOrEmpty(menu.CookBookNames))
                                    {
                                        // 显示多个菜谱名称
                                        var names = menu.CookBookNames.Split(',');
                                        <ul class="list-unstyled mb-0">
                                            @foreach (var name in names)
                                            {
                                                @if (!string.IsNullOrEmpty(name))
                                                {
                                                    <li>@name</li>
                                                }
                                            }
                                        </ul>
                                    }
                                    else if (!string.IsNullOrEmpty(menu.CookBookName))
                                    {
                                        // 显示单个菜谱名称（向后兼容）
                                        @menu.CookBookName
                                    }
                                }
                            }
                        </td>
                    }
                </tr>
            }
        </tbody>
    </table>

    <form asp-action="Delete" method="post">
        @Html.AntiForgeryToken()
        <input type="hidden" name="startDate" value="@ViewBag.StartDate" />
        <div class="form-group">
            <input type="submit" value="确认删除" class="btn btn-danger" />
            <a href="@Url.Action("Index")" class="btn btn-secondary">取消</a>
        </div>
    </form>
</div>